package com.yakumosakura.yakumoblade.entity.star;

import com.yakumosakura.yakumoblade.entity.MagicCircleEntity;
import com.yakumosakura.yakumoblade.entity.touhou.YukariEntity;
import com.yakumosakura.yakumoblade.registry.slashblade.YAEntitiesRegistry;
import mods.flammpfeil.slashblade.SlashBlade;
import mods.flammpfeil.slashblade.capability.concentrationrank.ConcentrationRankCapabilityProvider;
import mods.flammpfeil.slashblade.entity.EntityDrive;
import mods.flammpfeil.slashblade.entity.Projectile;
import mods.flammpfeil.slashblade.slasharts.Drive;
import mods.flammpfeil.slashblade.util.KnockBacks;
import mods.flammpfeil.slashblade.util.VectorHelper;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.network.PlayMessages;

public class StarRiderEntity extends MagicCircleEntity {
    public StarRiderEntity(EntityType<? extends Projectile> entityTypeIn, Level worldIn) {
        super(entityTypeIn, worldIn);
    }
    public static StarRiderEntity createInstance(PlayMessages.SpawnEntity packet, Level worldIn) {
        return new StarRiderEntity(YAEntitiesRegistry.StarRider, worldIn);
    }
    @Override
    protected void doEffect() {
        if (this.getOwner() instanceof LivingEntity livingEntity){
        doSlash( livingEntity,this);
        }
    }


    public static EntityDrive doSlash(LivingEntity playerIn,StarRiderEntity starRiderEntity) {
        if (playerIn.level().isClientSide()) {
            return null;
        } else {
             Vec3 centerOffset=Vec3.ZERO;
            Vec3 lookAngle = starRiderEntity.getLookAngle();
            Vec3 pos = starRiderEntity.position().add((double)0.0F,
                    (double)starRiderEntity.getEyeHeight() * (double)0.75F,
                    (double)0.0F).add(lookAngle.scale((double)0.3F));
            pos = pos.add(VectorHelper.getVectorForRotation(-90.0F,
                            starRiderEntity.getViewYRot(0.0F)).scale(centerOffset.y))
                    .add(VectorHelper
                            .getVectorForRotation(0.0F, starRiderEntity.getViewYRot(0.0F) + 90.0F)
                            .scale(centerOffset.z)).add(lookAngle.scale(centerOffset.z));
            EntityDrive drive = new EntityDrive(SlashBlade.RegistryEvents.Drive, starRiderEntity.level());
            drive.setPos(pos.x, pos.y, pos.z);
            drive.setDamage(1);
            drive.setSpeed(5f);
            Vec3 resultAngle = lookAngle.yRot(0.0f);
            drive.shoot(resultAngle.x, resultAngle.y, resultAngle.z, drive.getSpeed(), 0.0F);
            drive.setOwner(playerIn);
            drive.setRotationRoll(90);
            drive.setColor(14287103);
            drive.setLifetime(20f);

            playerIn.level().addFreshEntity(drive);
            return drive;
        }
    }
}
